package com.itcat.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itcat.api.mysql.CmsSubjectApi;
import com.itcat.mapper.CmsSubjectMapper;
import com.itcat.mysql.pojo.CmsSubject;
import com.itcat.mysql.pojo.SmsHomeAdvertise;
import com.itcat.mysql.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author Jerry Broker
 * @project_name rainbow-mall
 * @create 2022-04-03 14:49
 */
@DubboService
public class CmsSubjectApiImpl implements CmsSubjectApi {

    @Autowired
    private CmsSubjectMapper cmsSubjectMapper;

    /**
     * 获取全部商品专题
     * @return
     */
    @Override
    public List<CmsSubject> listAll() {
        List<CmsSubject> list = cmsSubjectMapper.selectList(null);
        return list;
    }

    /**
     * 分页获取商品专题
     * @param keyword
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public Page<CmsSubject>  list(String keyword, Integer pageNum, Integer pageSize) {
        Page<CmsSubject> page = new Page<>(pageNum,pageSize);

        LambdaQueryWrapper<CmsSubject> sqw = new LambdaQueryWrapper<>();
        sqw.like(keyword!=null,CmsSubject::getCategoryName,keyword);

        Page<CmsSubject> subjectPage = cmsSubjectMapper.selectPage(page, sqw);

        return subjectPage;
    }
}
